<?php
/**
 * Created by PhpStorm.
 * User: SongPeiLin
 * Date: 2018/9/30
 * Time: 10:17
 */

namespace app\admin\controller;


use app\admin\model\SzxinxiangModel;
use cmf\controller\AdminBaseController;
use think\Request;

class MsgListController extends AdminBaseController
{
    public  function index(){

    }

    //查询数据的方法
    public function msglist($where){
        //获取登录id
        $uid=cmf_get_current_admin_id();
        $where['dealunit']=$uid;
        $msgmod =new SzxinxiangModel();
        $res  = $msgmod->getMsgList($where);
        $count  = $msgmod->getCount($where);
        $res ->each(function($value,$key){
            $mod =new SzxinxiangModel();
            $unit['id']=$value['dealunit'];
            $unitname = $mod->getUnitname($unit);
            $value['unitname']=$unitname;
            return $value;
        });
        $res['count']=$count;
        return $res;
    }
    //获取市长信息列表来信待办列表
    public function getMsgList(){

        $where['deal'] =2;
        $msglist =$this->msglist($where);
        $this->assign('deal',2);
        $this->assign('count',$msglist['count']);
        unset($msglist['count']);
        $this->assign('page',$msglist->render());
        $this->assign('all',$msglist);
        return  $this->fetch('getmsg');

    }
    //来信已解决
    public function getMsgdeal(){

        //过滤非数字类型的参数

            $where['deal'] =3;
        $msglist =$this->msglist($where);
        if($msglist->isEmpty()){
            $this->error('未查询到相关内容');
        }
        $this->assign('count',$msglist['count']);
        unset($msglist['count']);
        $this->assign('all',$msglist);
        $this->assign('deal',3);
        $this->assign('page',$msglist->render());
       return  $this->fetch('getmsg');
    }
    //本单位已处理
    public function getMsgover(){

        $where['deal'] =4;
        $msglist =$this->msglist($where);
        if($msglist->isEmpty()){
            $this->error('未查询到相关内容');
        }
        $this->assign('count',$msglist['count']);
        $this->assign('all',$msglist);
        unset($msglist['count']);
        $this->assign('all',$msglist);
        $this->assign('deal',4);
        $this->assign('page',$msglist->render());
       return  $this->fetch('getmsg');
    }
    //查看详情
    public function getDetail(){
        $data =input('get.id');
        $id =filter_var($data,FILTER_SANITIZE_NUMBER_INT);
        $mod=new SzxinxiangModel();
        $where['id']=$id;
        $res = $mod->getMsgdet($where);
        //查询单位
        $unitid['id']=$res['dealunit'];
        $unitname=$mod->getUnitname($unitid);
        $res['unitname'] =$unitname;
        if($res){
            $deal =$res['deal'];
            switch($deal){
                case 2:
                     $this->assign('msg',$res);
                     return $this->fetch('content');
                    break;
                case 3:
                    $this->assign('msg',$res);
                    return $this->fetch('content2');
                    break;
                case 4:
                    $this->assign('msg',$res);
                    return $this->fetch('content2');
                    break;
            }

        }else{
            $this->error('未查询到信息');
        }
    }
    //更改解决状态
    public function editMsg(){
        $id=input('id');
        $deal=input('deal');
        $infoback=input('infoback');
        if($infoback){
            $data['infoback'] =trim($infoback);
        }
        $data['id'] =filter_var($id,FILTER_SANITIZE_NUMBER_INT);
        $data['deal'] =filter_var($deal,FILTER_SANITIZE_NUMBER_INT);

        $mod=new SzxinxiangModel();

        switch($deal){
            case 1:

                $res =$mod->upDeal($data);
                if($res){
                    $this->success('拒收成功', url('MsgList/getMsgList'));
                }else{
                    $this->error('未修改',url('MsgList/getMsgList'));
                }
            break;
            case 3:
                $data['overtime']=time();
                $res =$mod->upDeal($data);
                if($res){
                    $this->success('更改成功', url('MsgList/getMsgList'));
                }else{
                    $this->error('未修改',url('MsgList/getMsgList'));
                }
            break;
        }

    }
}
